package com.greenet.companytemplate.manager.service;

import com.greenet.companytemplate.base.service.CrudService;
import com.greenet.companytemplate.manager.dao.SecondMenuDao;
import com.greenet.companytemplate.manager.dao.ThirdMenuDao;
import com.greenet.companytemplate.manager.entity.Menu;
import com.greenet.companytemplate.manager.entity.TMenu;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by Administrator on 2016/4/27.
 */
@Service
public class ThirdMenuService extends CrudService<ThirdMenuDao,TMenu> {
    /**
     * 根据二级菜单的id，获得所有的三级菜单
     * @param id
     * @return
     * @throws Exception
     */
    public List<TMenu> getTidMenu(int id) throws Exception{
        return dao.getTidMenu(id);
    }

    /**
     * 将用户添加的三级菜单插入到数据库中
     * @param menu
     * @return
     */
    @Transactional(readOnly = false)
    public int insert(TMenu menu){
        dao.insert(menu);
        return Integer.parseInt(menu.getId());
    }

    /**
     * 更新三级菜单的url（用户上传文件的路径）
     * @param menu
     */
    @Transactional(readOnly = false)
    public void updateUrl(TMenu menu){
        dao.updateUrl(menu);
    }

    /**
     * 根据菜单名称查询菜单，去重用
     * @param name
     * @return
     */
    public List<TMenu> getMenuByName(String name){
        return dao.getMenuByName(name);
    }
}
